//
//  HEIMMsgCell.m
//  HealthElderly
//
//  Created by 吴欧 on 2020/12/23.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEIMMsgCell.h"
#import "HEDocImMsgModel.h"

@interface HEIMMsgCell ()

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UILabel *timeLb;

@property (nonatomic, strong) UILabel *hospLb;
@property (nonatomic, strong) UILabel *tagLb;
@property (nonatomic, strong) UILabel *descLb;

@end

@implementation HEIMMsgCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = CLightGrayColor;
     
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
 
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    warp.layer.cornerRadius = 8;
 
    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    
    // 头像
    _goodsimgView = [UIImageView new];
    _goodsimgView.image = IMAGE_NAMED(@"noImage");
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];

    // 姓名
    _titleLb = [UILabel new];
    _titleLb.text = @"";
    _titleLb.font = DYBlodFont(18);
    _titleLb.numberOfLines = 1;
    [warp addSubview:_titleLb];

    _timeLb = [UILabel new];
    _timeLb.text = @"";
    _timeLb.font = DYFont(16);
    _timeLb.textColor = CNavDargGrayColor;
    [warp addSubview: _timeLb];
    
    
    // 所属医院
    _hospLb = [UILabel new];
    _hospLb.text = @"";
    _hospLb.font = DYFont(15);
    _hospLb.textColor = CNavLightBlackColor;
    _hospLb.numberOfLines = 0;
    [warp addSubview:_hospLb];

    // 标签   我的医生 \ 关注
    _tagLb = [UILabel new];
    _tagLb.text = @"私人";
    _tagLb.backgroundColor = KHexColor(@"F2791C");
    _tagLb.textColor = KWhiteColor;
    _tagLb.font = DYBlodFont(14);
    _tagLb.textAlignment = NSTextAlignmentCenter;
    [warp addSubview:_tagLb];
    _tagLb.layer.cornerRadius = 3;
    _tagLb.layer.masksToBounds = YES;

    // 描述
    _descLb = [UILabel new];
    _descLb.text = @"";
    _descLb.font = DYFont(16);
    _descLb.textColor = CGrayColor;
    _descLb.numberOfLines = 1;
    _descLb.lineBreakMode = NSLineBreakByCharWrapping;
    [warp addSubview:_descLb];
     
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(warp).mas_offset(15);
       make.left.equalTo(warp).mas_offset(15);
       make.width.height.mas_offset(50);
    }];
    _goodsimgView.layer.masksToBounds = YES;
    _goodsimgView.layer.cornerRadius = 25;
 
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).mas_offset(15);
        make.left.equalTo(_goodsimgView.mas_right).offset(15);
        make.right.equalTo(_timeLb.mas_left).mas_offset(-10);
    }];
    [_titleLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    
    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.right.equalTo(warp).offset(-15).priorityHigh();
    }];
    [_timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];


    [_hospLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(5);
        make.left.equalTo(_titleLb.mas_left);
        make.right.equalTo(_tagLb.mas_left).mas_offset(-20);
    }];
    [_hospLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_hospLb);
        make.right.equalTo(warp.mas_right).mas_offset(-15);
        make.width.mas_offset([_tagLb.text widthForFont:_tagLb.font] + 10);
        make.height.mas_offset([_tagLb.text heightForFont:_tagLb.font width:[_tagLb.text widthForFont:_tagLb.font]] + 5);
    }];
    
    UIView *bottomLine = [UIView new];
    bottomLine.backgroundColor = CSplitLineColor;
    [self.contentView addSubview:bottomLine];

    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_hospLb.mas_bottom).mas_offset(15);
        make.left.equalTo(warp).mas_offset(10);
        make.right.equalTo(warp).mas_offset(-10);
        make.height.offset(1);
    }];

    [_descLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomLine.mas_bottom).mas_offset(15);
        make.left.equalTo(warp.mas_left).mas_offset(15);
        make.right.equalTo(warp.mas_right).mas_offset(-15);
        make.bottom.equalTo(warp.mas_bottom).mas_offset(-15);
    }];
  
}


- (void)configCellWithModel:(HEDocImMsgModel *)model {
 
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:model.KAvatar] placeholderImage:IMAGE_NAMED(@"defualt_icon")];
    _titleLb.text = model.KTitleName;
    _timeLb.text = model.Kcreate_date;
    _hospLb.text = model.KHospAndDept;
    _descLb.text = model.Kmsg;
    _tagLb.text = model.KTag;
    _tagLb.backgroundColor = model.KTagColor;
    
    [self showbadge: !model.KIsRead];
}

- (void)showbadge:(BOOL)show {
  
    if (show) {
        [_timeLb pp_showBadge];
  
        _timeLb.badgeView.font = DYBlodFont(14);
        [_timeLb pp_addDotWithColor: CPriceColor];
        [_timeLb pp_setBadgeHeight: 12];
        [_timeLb pp_moveBadgeWithX: 5 Y: 0];
    }else {
        [_timeLb pp_hiddenBadge];
    }
}

@end

